home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*----------------------------------------------------------------
- *
- * lackey - speech recognition based application launcher
- *
- * 08/93 John Magdziarz, Silicon Graphics, Inc.
- *
- *----------------------------------------------------------------*/
-
- #include <stream.h>
- #include <assert.h>
-
- #include <speech/Recognizer.h>
- #include <speech/Word.h>
- #include <speech/Database.h>
- #include <speech/WordCallbackBindings.h>
- #include <speech/Vocabulary.h>
- #include <speech/Condition.h>
- #include <speech/CharString.h>
-
- class NameCommand
- {
- public:
- char *name;
- char *command;
- };
-
-
- SpeechWord *appWord;
-
-
- long
- launchApp( const SpeechWord&, void* v )
- {
- FILE *fid;
-
- cout << v << endl;
- char *tmpStr = new(char[strlen((char *)v) + 2]);
- char *cmd;
-
- strcpy(tmpStr, (char *)v);
- strtok( (char *)tmpStr, " ");
- // check if app exists by trying to open it for read
- if ((fid = fopen(tmpStr, "r")) == NULL) {
- system("playaifc -p -q not_found.aifc &");
- return 0;
- }
- fclose(fid);
- strcpy(tmpStr, (char *)v);
- strcat(tmpStr,"&");
- if (system(tmpStr) != NULL)
- cerr << "error executing system command\n" << flush;
- return 1;
- }
-
-
- int main( int argc, char* argv[] )
- {
- char* applicationClass = "Lackey" ;
- char* applicationName = argv[0] ;
- const NameCommand apps[] = {
- { "lackey", "/usr/sbin/playaifc -p -q serve.aifc"},
- { "clock", "/usr/bin/X11/xclock"},
- { "apanel", "/usr/sbin/apanel" },
- { "shell", "/usr/sbin/xwsh" },
- { (char *)0, (char *)0 },
- };
-
- XrmDatabase xrmDatabase // toolkit-dependent
- = XrmGetFileDatabase( CharString( CharString(getenv( "HOME" ) ))
- + CharString("/.Xdefaults" )) ;
-
- SpeechRecognizer recognizer( applicationClass, applicationName, xrmDatabase,
- "", // default display, program name
- SpeechRecognitionEventInterest // get recognition events and all others
- | SpeechPoorMatchEventInterest
- | SpeechAmbiguousMatchEventInterest
- | SpeechErrorEventInterest ) ;
- assert( recognizer.status( ) == SpeechOK ) ;
-
- int i = 0;
- while (apps[i].name) {
- appWord = new SpeechWord( (const char*)apps[i].name,
- (const char*)apps[i].name,
- recognizer,
- (const SpeechCallbackFunctionPointer) launchApp,
- (void *)apps[i].command,
- SpeechCondition( SpeechConditionGlobal ));
- i++;
- if( recognizer.status() != SpeechOK )
- cerr << "trouble loading global words\n" << flush ;
- }
-
- system("/usr/sbin/playaifc -p -q awaitcmd.aifc &");
- // toolkit-dependent modification here
- XEvent event ;
- do
- {
- XNextEvent( recognizer.dpy(), &event ) ;
- if( recognizer.isSpeechEvent( &event ) )
- recognizer.processEvent( &event ) ;
- else
- ; // process as other/normal event
- } while( event.type != DestroyNotify ) ; // just to get rid of warning
-
- XrmDestroyDatabase( xrmDatabase ) ;
-
- return recognizer.status( ) ;
- }
-